<script type="text/javascript">
    $.CurrentNavtab.find("#base_id").on("change", function() {
        var baseId = $(this).val();
        $.post("{:U('Admin/Block/getBaseBlock')}", {"baseId":baseId}, function(res) {
            var opt = "<option value='0'>请选择</option>";
            if(res["statusCode"] == 200) {
                var list = res["data"]["list"];
                for(var ix = 0; ix < list.length; ++ix) {
                    opt += "<option value='" + list[ix]["id"] + "'>" + list[ix]["sn"] + "</option>";
                }
            }
            $.CurrentNavtab.find("#block_id").html(opt);
        }, "json");
    });
    
    $.CurrentNavtab.find("#large_type").on("change", function() {
        var typeId = $(this).val();
        $.post("{:U('Admin/Type/getChildType')}", {"typeId":typeId}, function(res) {
            var opt = "<option value='0'>请选择</option>";
            if(res["statusCode"] == 200) {
                var list = res["data"]["list"];
                for(var ix = 0; ix < list.length; ++ix) {
                    opt += "<option value='" + list[ix]["id"] + "'>" + list[ix]["name"] + "</option>";
                }
            }
            $.CurrentNavtab.find("#small_type").html(opt);
        }, "json");
    });
    
    $.CurrentNavtab.find("#small_type").on("change", function() {
        var typeId = $(this).val();
        $.post("{:U('Admin/Tree/getTreeTypeAttr')}", {"typeId":typeId,"isSearch":1}, function(res) {
            var attr = "";
            if(res["statusCode"] == 200) {
                attr = res["data"]["attrStr"];
            }
            $.CurrentNavtab.find("#treeAttrSearch").html(attr);
        }, "json");
    });
    
    $.CurrentNavtab.find("#exportExcelBtn").on("click", function() {
        var form = $.CurrentNavtab.find("#pagerForm");
        var href = "{:U('Admin/Tree/exportExcel')}" + "?" + form.serialize();
        $.fileDownload(href).done(function() {
            
        }).fail(function() {
            $.alertmsg("warn", "导出失败");
        });
        return false;
    });
    
    $.CurrentNavtab.find("#exportPrintExcelBtn").on("click", function() {
        var form = $.CurrentNavtab.find("#pagerForm");
        var href = "{:U('Admin/Tree/exportPrintExcel')}" + "?" + form.serialize();
        $.fileDownload(href).done(function() {
            $(this).navtab("refresh", "Admin/Tree/treeList");
        }).fail(function() {
            $.alertmsg("warn", "导出失败");
        });
        return false;
    });
    
    $.CurrentNavtab.find("#batchSetTreeStatusBtn").on("click", function() {
        var chkbox = $.CurrentNavtab.find("input[name='ids']:checked");
        
        if(chkbox.length == 0) {
            $(this).alertmsg("warn", "请选择苗木");
            return false;
        }
        
        var ids = "";
        $.each(chkbox, function() {
            ids += $(this).val() + ",";
        });
        $(this).dialog({url:"{:U('Admin/Tree/batchSetTreeStatus')}" + "/ids/" + ids, title:'批量设置苗木状态', height:'160'});
    });
</script>
<style>
    #treeAttrSearch .attrRow {display:inline-block;margin:0 5px;}
</style>
<div class="bjui-pageHeader">
    <form id="pagerForm" data-toggle="ajaxsearch" action="{:U('Admin/Tree/treeList')}" method="post">
        <input type="hidden" name="pageSize" value="{$pageSize}">
        <input type="hidden" name="pageCurrent" value="{$pageCurrent}">
        <input type="hidden" name="orderField" value="{$orderField}">
        <input type="hidden" name="orderDirection" value="{$orderDirection}">
        <div class="bjui-searchBar">
            <label>基地名称：</label>
            <select name="base_id" id="base_id" class="form-control" style="width:150px;">
                <option value="0">请选择</option>
                <notempty name="base">
                    <foreach name="base" item="vo" key="k">
                        <option value="{$vo.id}" <if condition="$vo['id'] eq $params['base_id']">selected="selected"</if>>{$vo.name}</option>
                    </foreach>
                </notempty>
            </select>
            <label>地块编号：</label>
            <select name="block_id" id="block_id" class="form-control" style="width:150px;">
                <option value="0">请选择</option>
                <notempty name="block">
                    <foreach name="block" item="vo" key="k">
                        <option value="{$vo.id}" <if condition="$vo['id'] eq $params['block_id']">selected="selected"</if>>{$vo.sn}</option>
                    </foreach>
                </notempty>
            </select>
            <label>苗木分类：</label>
            <select name="large_type" id="large_type" class="form-control" style="width:150px;">
                <option value="0">请选择</option>
                <notempty name="largeType">
                    <foreach name="largeType" item="vo" key="k">
                        <option value="{$vo.id}" <if condition="$vo['id'] eq $params['large_type']">selected="selected"</if>>{$vo.name}</option>
                    </foreach>
                </notempty>
            </select>
            <label>苗木种类：</label>
            <select name="small_type" id="small_type" class="form-control" style="width:150px;">
                <option value="0">请选择</option>
                <notempty name="smallType">
                    <foreach name="smallType" item="vo" key="k">
                        <option value="{$vo.id}" <if condition="$vo['id'] eq $params['small_type']">selected="selected"</if>>{$vo.name}</option>
                    </foreach>
                </notempty>
            </select>
            <button type="submit" class="btn-default" data-icon="search">查询</button>&nbsp;
            <a class="btn btn-orange" href="javascript:;" onclick="$(this).navtab('reloadForm', true);" data-icon="undo">清空查询</a>
        </div>
        <div id="treeAttrSearch" class="bjui-searchBar" style="height:25px;margin:5px 0;">
            <notempty name="treeAttr">
            {$treeAttr}
            </notempty>
        </div>
    </form>
    <div style="margin:10px 0;">
        <if condition="checkRule('Admin/Tree/addOneTree')">
        <a class="btn btn-green" href="{:U('Admin/Tree/addOneTree')}" data-toggle="navtab" data-id="Admin/Tree/addOneTree">单棵添加</a>
        </if>
        <if condition="checkRule('Admin/Tree/addMoreTree')">
        <a class="btn btn-green" href="{:U('Admin/Tree/addMoreTree')}" data-toggle="navtab" data-id="Admin/Tree/addMoreTree">批量添加</a>
        </if>
        <if condition="checkRule('Admin/Tree/delTree')">
        <a class="btn btn-red" href="{:U('Admin/Tree/delTree')}" data-toggle="doajaxchecked" data-confirm-msg="确定要删除选中苗木吗？" data-idname="ids" data-group="ids">批量删除</a>
        </if>
        <if condition="checkRule('Admin/Tree/batchSetTreeStatus')">
        <a class="btn btn-green" href="javascript:void(0);" id="batchSetTreeStatusBtn">批量设置苗木状态</a>
        </if>
        <if condition="checkRule('Admin/Tree/exportExcel')">
        <a class="btn btn-green" id="exportExcelBtn">导出EXCEL</a>
        </if>
        <if condition="checkRule('Admin/Tree/exportPrintExcel')">
        <a class="btn btn-green" id="exportPrintExcelBtn">导出打印EXCEL</a>
        </if>
        
        <!--
        <if condition="checkRule('Admin/Tree/labelPrint')">
        <a class="btn btn-green" href="{:U('Admin/Tree/labelPrint')}" data-toggle="doajaxchecked" data-confirm-msg="确定要打印选中苗木吗？" data-idname="ids" data-group="ids">标签打印</a>
        </if>
        -->
        
        <if condition="checkRule('Admin/Tree/importExcel')">
        <a class="btn btn-green" data-url="{:U('Admin/Tree/importExcel')}" data-toggle="dialog">批量导入</a>
        </if>
        <a class="btn btn-green" href="{:U('Admin/Tree/importTemplate')}">导入模板下载</a>
    </div>
</div>
<div class="bjui-pageContent tableContent">
    <table data-toggle="tablefixed" data-width="100%" data-nowrap="true">
        <thead>
            <tr>
                <th width="26"><input type="checkbox" class="checkboxCtrl" data-group="ids" data-toggle="icheck"></th>
                <th data-order-field="t.sn">苗木编号</th>
                <th>苗木分类</th>
                <th>苗木种类</th>
                <th data-order-field="t.row">行</th>
                <th data-order-field="t.col">列</th>
                <th>自有属性</th>
                <th>状态</th>
                <th>所属地块</th>
                <th>是否挂牌</th>
                <th data-order-field="t.add_time">添加时间</th>
                <th width="100">操作</th>
            </tr>
        </thead>
        <tbody>
        <notempty name="list">
            <foreach name="list" item="vo" key="k">
                <tr data-id="{$vo.id}">
                    <td><input type="checkbox" name="ids" data-toggle="icheck" value="{$vo.id}"></td>
                    <td>{$vo.sn}</td>
                    <td>{$vo.large_name}</td>
                    <td>{$vo.small_name}</td>
                    <td>{$vo.row}</td>
                    <td>{$vo.col}</td>
                    <td>{$vo.attr}</td>
                    <td>{$vo.status}</td>
                    <td>{$vo.block_sn}</td>
                    <td>{$vo.is_sign}</td>
                    <td>{$vo.add_time}</td>
                    <td>
                        <if condition="checkRule('Admin/Tree/updTree')">
                            <a href="{:U('Admin/Tree/updTree', array('treeId' => $vo['id']))}" class="btn btn-green" data-toggle="navtab" data-id="Admin/Tree/updTree">编辑</a>
                        </if>
                        <if condition="checkRule('Admin/Tree/delTree')">
                            <a href="{:U('Admin/Tree/delTree', array('ids' => $vo['id']))}" class="btn btn-red" data-toggle="doajax" data-confirm-msg="确定要删除该苗木吗？">删</a>
                        </if>
                    </td>
                </tr>
            </foreach>
        </notempty>
        </tbody>
    </table>
</div>
<div class="bjui-pageFooter">
    <div class="pages">
        <span>每页&nbsp;</span>
        <div class="selectPagesize">
            <select data-toggle="selectpicker" data-toggle-change="changepagesize">
                <option value="30" <if condition="$pageSize eq 30">selected="selected"</if>>30</option>
                <option value="60" <if condition="$pageSize eq 60">selected="selected"</if>>60</option>
                <option value="120" <if condition="$pageSize eq 120">selected="selected"</if>>120</option>
                <option value="150" <if condition="$pageSize eq 150">selected="selected"</if>>150</option>
            </select>
        </div>
        <span>&nbsp;条，共 {$total} 条</span>
    </div>
    <div class="pagination-box" data-toggle="pagination" data-total="{$total}" data-page-size="{$pageSize}" data-page-current="{$pageCurrent}"></div>
</div>